﻿/*================================================================================================
	TASK 10:                                                                 {Console InputOutput}
	Write a program to calculate the sum (with accuracy of 0.001): 1 + 1/2 - 1/3 + 1/4 - 1/5 + ...     
================================================================================================*/

using System;

class Program
{
    static void Main()
    {
        decimal a = 1;
        decimal oldSum,newSum=1;
        int i;

        Console.WriteLine("a1={0}", a);

        for (i = 1; i <= 600; i++)
        {
            a = 1M / (2 * i);
            oldSum = newSum + a;

            Console.WriteLine("a{0}={1}", 2 * i, a);
            //Console.WriteLine("oldSum={0}", oldSum);

            a = -(1M / ((2 * i) + 1));
            newSum = oldSum + a;

            Console.WriteLine("a{0}={1}", 2 * i + 1, a);
            //Console.WriteLine("newSum={0}", newSum);
            
            if (Math.Abs(oldSum - newSum) >= 0.001M)
            {
                Console.WriteLine("old-new={0}>0.001", Math.Abs(oldSum - newSum));
            }
            else
            {
                Console.WriteLine("old-new={0}<0.001", Math.Abs(oldSum - newSum));
                break;
            }
        }
    }
}

